from flask import Flask, jsonify, request
from myquery import CorridorPedestrianReid

detector = CorridorPedestrianReid()

app = Flask(__name__)

@app.route("/Reid", methods=['POST'])
def Reid():
    # 2. 读取字节流
    image_bytes = request.data
    if len(image_bytes) == 0:
        return jsonify({"status": "error", "message": "Empty image data"}), 400
    original_img, locations, pids = detector.detect_and_recognize_by_vector_redis_database(image_bytes)

    # 打印结果
    print("检测到的行人位置:", locations)
    print("对应的PID:", pids)

    return jsonify({
        "locations": locations,  # [[x1,y1,x2,y2], ...]
        "pids": pids,  # [pid1, pid2, ...]
    })

if __name__ == '__main__':
    app.run(host="0.0.0.0", port=5000)